// components/st-search/st-search.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    searchVal: { // 搜索目标
      type: String,
      value: ''
    },
    isSearch: { // 是否展示input
      type: Boolean,
      value: true
    },
    showChoose: { // 是否展示筛选项
      type: Boolean,
      value: true
    }, 
    showSearch: { // 是否展示搜索结果
      type: Boolean,
      value: true
    }, 
    searchTxt:{
      type:String,// 按钮文案
      value:'筛选'
    },
    showTxt:{
      type:String,// 是否显示按钮
      value: 'true'
    },
    searchImg:{
      type:String,// 按钮图片
      value:'/images/choose.png'
    },
    paddingRight:{
      type:String,// 按钮图片
      value:'118'
    },

  },

  /**
   * 组件的初始数据
   */
  data: {
    showChoose:false,
    searchVal: "",
    showSearch:true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    change(e){
      // console.log(e,this.data);
      this.setData({
        isSearch:!this.data.isSearch
      })
    },
    loseFocus(e){
      this.setData({
        isSearch:!this.data.isSearch,
      })
      this.showSearchList()
    },
    clearVal(e){
      this.setData({
        searchVal:'',
      })
      this.triggerEvent('clearVal', {showSearch:true})
    },
    showSearchList(){
      let showSearch = !this.data.showSearch
      this.triggerEvent('showSearchList', {showSearch})
    },
    setVal(e){
      this.setData({
        searchVal:e.detail.value
      })
    },
    chooseEvent(e){
      let showChoose = !this.data.showChoose;
      this.setData({
        showChoose:showChoose
      })
      this.triggerEvent('chooseEvent', {showChoose})
    },
    confirmSearch(e){
      this.triggerEvent('confirmSearch',{searchVal:e.detail.value})
      console.log('confirmSearch',e);
    }
  }
})
